//
//  UINavigationBar+ChanheAlpha.m
//  YUXiu
//
//  Created by 王竞成 on 16/6/23.
//  Copyright © 2016年 Wang. All rights reserved.
//

#import "UINavigationBar+ChanheAlpha.h"
#import <objc/runtime.h>

const void *overLay;

@implementation UINavigationBar (ChanheAlpha)

- (void)setOverlayView:(UIView *)overlayView {
    objc_setAssociatedObject(self, &overLay, overlayView, OBJC_ASSOCIATION_RETAIN);
}

- (UIView *)overlayView {
    return objc_getAssociatedObject(self, &overLay);
}

/**
 *  @author 刘俊, 15-10-22
 *  变透明
 */
- (void)Transparent {
    [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    self.shadowImage = [UIImage new];
    if (!self.overlayView) {
        self.overlayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64)];
        self.overlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    }
    [self.superview insertSubview:self.overlayView belowSubview:self];
}

- (void)NotTransparent {
    [self.overlayView removeFromSuperview];
    //    self.overlayView = nil;
    [self setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}

- (void)ChangeNavigationBarColor:(UIColor *)color Alpha:(CGFloat)alpha {
    [self ChangeNavigationBarColor:[color colorWithAlphaComponent:alpha]];
}
- (void)ChangeNavigationBarColor:(UIColor *)color {
    
    self.overlayView.backgroundColor = color;
    
}


@end
